home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / amiga / asrc29k.lha / arpdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  1.7 KB  |  75 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "timer.h"
  5. #include "arp.h"
  6. #include "netuser.h"
  7. #include "trace.h"
  8.  
  9. void arp_dump(fp,bpp)
  10. FILE *fp;
  11. struct mbuf **bpp;
  12. {
  13.     struct arp arp;
  14.     struct arp_type *at;
  15.     int is_ip = 0;
  16.     char tmp[25];
  17.  
  18.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  19.         return;
  20.     fprintf(fp,"ARP: len %d",len_p(*bpp));
  21.     if(ntoharp(&arp,bpp) == -1){
  22.         fprintf(fp," bad packet\n");
  23.         return;
  24.     }
  25.     if(arp.hardware < NHWTYPES)
  26.         at = &Arp_type[arp.hardware];
  27.     else
  28.         at = NULLATYPE;
  29.  
  30.     /* Print hardware type in Ascii if known, numerically if not */
  31.     fprintf(fp," hwtype %s",smsg(Arptypes,NHWTYPES,arp.hardware));
  32.  
  33.     /* Print hardware length only if unknown type, or if it doesn't match
  34.      * the length in the known types table
  35.      */
  36.     if(at == NULLATYPE || arp.hwalen != at->hwalen)
  37.         fprintf(fp," hwlen %u",arp.hwalen);
  38.  
  39.     /* Check for most common case -- upper level protocol is IP */
  40.     if(at != NULLATYPE && arp.protocol == at->iptype){
  41.         fprintf(fp," prot IP");
  42.         is_ip = 1;
  43.     } else {
  44.         fprintf(fp," prot 0x%x prlen %u",arp.protocol,arp.pralen);
  45.     }
  46.     switch(arp.opcode){
  47.     case ARP_REQUEST:
  48.         fprintf(fp," op REQUEST");
  49.         break;
  50.     case ARP_REPLY:
  51.         fprintf(fp," op REPLY");
  52.         break;
  53.     case REVARP_REQUEST:
  54.         fprintf(fp," op REVERSE REQUEST");
  55.         break;
  56.     case REVARP_REPLY:
  57.         fprintf(fp," op REVERSE REPLY");
  58.         break;
  59.     default:
  60.         fprintf(fp," op %u",arp.opcode);
  61.         break;
  62.     }
  63.     fputc('\n',fp);
  64.  
  65.     fprintf(fp,"     sender");
  66.     if(is_ip)
  67.         fprintf(fp," IPaddr %s",inet_ntoa(arp.sprotaddr));
  68.     fprintf(fp," hwaddr %s\n",at->format(tmp,arp.shwaddr));
  69.  
  70.     fprintf(fp,"     target");
  71.     if(is_ip)
  72.         fprintf(fp," IPaddr %s",inet_ntoa(arp.tprotaddr));
  73.     fprintf(fp," hwaddr %s\n",at->format(tmp,arp.thwaddr));
  74. }
  75.